import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Work2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();

        StringBuilder s = new StringBuilder();
        String table = "0123456789ABCDEF";
        boolean flag = false;
        if (m < 0) {
            m = -m;
            flag = true;
        }
        if (m == 0) {
            s.append("0");
        }
        while (m != 0) {
            s.append(table.charAt(m % n));
            m = m / n;
        }
        if (flag) {
            s.append("-");
        }
        //逆置
        s.reverse();
        System.out.println(s);
    }
}
